<template>
	<view class="parent-clue-details">
		<view class="parent-clue-details-img"></view>
		<view class="parent-clue-details-card">
			<view class="">
				<image :src="parentClueDetails.avatar" mode="" style="width: 120upx; height: 120upx; vertical-align: middle; border-radius: 90upx;"></image>
				<view class="" style="display: inline-block; margin-left: 20upx; vertical-align: middle;margin-top: 8upx;">
					<view class="" style="font-size: 32upx; font-weight: bold; height: 46upx;">{{parentClueDetails.nickname}}</view>
					<view class="" style="font-size: 28upx; margin-top: 30upx;">手机号：{{parentClueDetails.phone}}</view>
				</view>
				<button class="copynikename-btn" style="color: #FF664F; background-color: #ffffff;" type="default" @click="copyData(parentClueDetails.nickname)">复制昵称</button>
				<button class="callphone-btn" style="color: #FFFFFF;" type="default" @click="callPhone(parentClueDetails.phone)">拨打电话</button>
			</view>
			<view style="height: 2upx; background-color: #F2F2F2; margin: 50upx 0upx 30upx 0upx;"></view>
			<view class="" style="font-size: 26upx; color: rgba(0,0,0,0.45);">
				<view class="" style="margin-bottom: 10upx;">
					第1次到店时间：{{ parentClueDetails.first_time | formatDates }}
				</view>
				<view class="">
					最近到店时间：{{ parentClueDetails.recent_time | formatDates }}
				</view>
			</view>
			<view style="height: 2upx; background-color: #F2F2F2; margin: 30upx 0upx 30upx 0upx;"></view>
			<view class="" style="font-size: 26upx; margin-top: 20upx; text-align: center; font-weight: bold;">
				<view style="display: inline-block; position: absolute; left: 65upx;">
					到访次数：<view style="display: inline-block; color: red;">{{parentClueDetails.access_num}}</view>次
				</view>
				<view style="display: inline-block;">
					分享次数：<view style="display: inline-block; color: red;">{{parentClueDetails.share_num}}</view>次
				</view>
				<view style="display: inline-block; position: absolute; right: 70upx;">
					邀请人数：<view style="display: inline-block; color: red;">{{parentClueDetails.invite_num}}</view>人
				</view>
			</view>
		</view>
		
		<view class="parent-clue-details-content">
			<view class="parent-clue-details-nav">
				<view class="group-state-contain">
					<view :class="groupStatusIndex==index?'group-state-active':''" v-for="(item,index) in userclue" :key='index' data-index="index" @click="changeIndex(index)">
						{{item}}
					</view>
				</view>
			</view>
			<!-- 浏览历史 -->
			<view class="parent-clue-details-block" v-for="(history,num) in parentClueDetails.detail" :key="num" v-if="groupStatusIndex == 0">
				<image class="parent-clue-details-block-img" :src="history.image || history.head_img" mode=""></image>
				<view class="parent-clue-details-block-title">
					{{ history.name || history.video_detail }}
				</view>
				<view class="" style="font-size: 24upx; color: rgba(0,0,0,0.65);">
					<view class="" style="display: inline-block;">
						访问时间：{{ history.access_time | formatDates }}
					</view>
				</view>
				<view style="height: 2upx; background-color: #F2F2F2; margin: 40upx 0upx 40upx 0upx;"></view>
			</view>
			<!-- 邀请人员明细 -->
			<view class="parent-clue-details-content-people" v-if="groupStatusIndex == 1">
				<view class="" v-for="(invitees,number) in inviteesDetailed" :key="number" @click="historys(invitees.customer_id)">
					<view class="">
						<image :src="invitees.avatar" mode="" style="width: 120upx; height: 120upx; vertical-align: middle; border-radius: 90upx;"></image>
						<view class="" style="display: inline-block; margin-left: 30upx; vertical-align: middle;margin-top: 8upx;">
							<view class="" style="font-size: 32upx; font-weight: bold;">{{invitees.nickname}}</view>
							<view class="" style="margin-top: 18upx;">第1次到店时间: {{invitees.first_time | formatDates}}</view>
						</view>
						<view class="arrow" ></view>
					</view>
					<view class="" style="font-size: 24upx; margin-top: 20upx; text-align: center;">
						<view style="display: inline-block; position: absolute; left: 65upx;">
							到访次数：<view style="display: inline-block; color: red;">{{invitees.access_num}}</view>次
						</view>
						<view style="display: inline-block;">
							分享次数：<view style="display: inline-block; color: red;">{{invitees.share_num}}</view>次
						</view>
						<view style="display: inline-block; position: absolute; right: 70upx;">
							邀请人数：<view style="display: inline-block; color: red;">{{invitees.invite_num}}</view>人
						</view>
					</view>
					<view v-if="number < inviteesDetailed.length-1" style="height: 2upx; background-color: #F2F2F2; margin: 40upx 0upx 40upx 0upx;"></view>
				</view>
			</view>
		</view>
		
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				customer_id:'',
				groupStatusIndex:0,
				userclue:['浏览历史','邀请人员明细'],
				// 家长线索明细
				parentClueDetails:[
					
				],
				// 邀请人员明细
				inviteesDetailed:[
					
				]
			}
		},
		onLoad(options){
			this.customer_id = parseInt(options.customer_id,10)
			console.log('进入了onload 获取url的customer_id',this.customer_id)
			this.getInviteesDetailed()
			this.getParentClueDetails()
		},
		filters: {
			getStr(str, new_length) {
			// console.log('getStr', str);
				if (!str) {
					return ''
				}
				if (str.length > new_length) {
					return str.slice(0, new_length) + '...'
				} else {
					return str
				}
			},
			// 时间戳转换
			formatDates(value) {
				let date = new Date(value * 1000);
				let y = date.getFullYear();
				let MM = date.getMonth() + 1;
				MM = MM < 10 ? ('0' + MM) : MM;
				let d = date.getDate();
				d = d < 10 ? ('0' + d) : d;
				return y + '-' + MM + '-' + d;
			}
		},
		methods: {
			// 浏览记录
			historys(customer_id){
				uni.navigateTo({
					url:"parentClueDetails?topNavActiveIndex=0&customer_id="+customer_id
				})
			},
			changeIndex(index){
				this.groupStatusIndex = index
			},
			// 复制昵称
			// #ifdef H5
				copyData(copyText) {
					console.log('点击了复制');
					let content = copyText // 复制内容，必须字符串，数字需要转换为字符串
					const result = h5Copy(content)
					if (result === false) {
						uni.showToast({
							title: '不支持',
						})
					} else {
						uni.showToast({
							title: '复制成功',
							icon: 'none'
						})
					}
				},
			// #endif
			// #ifdef MP-WEIXIN
				copyData(wechatNumber) {
					uni.setClipboardData({
						data: wechatNumber,
						success: function (res) {
							uni.getClipboardData({
								success: function (res) {
									console.log(res.data) // data
								}
							})
						}
					})
				},
			// #endif
			// 拨打
			callPhone(phone) {
				uni.makePhoneCall({
					phoneNumber: phone,
					success(res) {
						console.log(res)
					},
					fail(err) {
						console.log(err)
					}
				})
			},
			// 获取邀请人员明细
			getInviteesDetailed(){
				console.log("getInviteesDetailed",this.$store.getters.getToken)
				let data = {
					token:this.$store.getters.getToken,
					customer_id:this.customer_id,
					store_id:this.$store.getters.getStoreId,
				}
				console.log("8888888",data);
				// 3.发送请求
				this.$api.get_inviteesDetailed(data).then(res => {
					console.log(res,"545454");
					if(res.status){
						this.inviteesDetailed = res.msg.userInfo
						console.log(this.inviteesDetailed,'邀请人员明细')
					}else{
						uni.showToast({
							title:res.msg,
							icon:'none',
							duration:2000
						})
					}
				}).catch(err =>{
					console.log(err)
				})
			},
			// 获取家长线索明细
			getParentClueDetails(){
				console.log("getParentClueDetails",this.$store.getters.getToken)
				let data = {
					token:this.$store.getters.getToken,
					customer_id:this.customer_id,
					store_id:this.$store.getters.getStoreId,
				}
				console.log("8888888");
				// 3.发送请求
				this.$api.get_parentClueDetails(data).then(res => {
					console.log(res,"545454");
					if(res.status){
						this.parentClueDetails = res.msg.userInfo
						console.log(this.parentClueDetails,'家长线索明细')
					}else{
						uni.showToast({
							title:res.msg,
							icon:'none',
							duration:2000
						})
					}
				}).catch(err =>{
					console.log(err)
				})
			}
		}
	}
</script>

<style>
	.parent-clue-details{
		background-color: #eaeaea;
		height: 100%; 
		width: 100%; 
		padding-bottom: 70upx;
	}
	.parent-clue-details-img{
		width: 100%;
		height: 300upx;
		background-image: url(https://tool.tuanhaoke.cn/static/image/member/member-center.png);
	}
	.parent-clue-details-card{
		margin: 30upx;
		margin-top: -220upx;
		padding: 50upx 35upx 30upx 35upx;
		border-radius: 16upx;
		background-color: #ffffff;
	}
	.copynikename-btn{
		position: absolute;
		display: inline-block;
		right: 60upx;
		width: 160upx;
		line-height: 45upx;
		font-size: 24upx;
		border-radius: 15upx;
		background-color: #ffffff;
		border: 1upx solid #FF664F;
		color: #FF664F;
		border-radius: 45upx;
		margin-top: 6upx;
		vertical-align: middle;
	}
	.callphone-btn{
		position: absolute;
		display: inline-block;
		right: 60upx;
		width: 160upx;
		line-height: 45upx;
		font-size: 24upx;
		border-radius: 15upx;
		color: #ffffff;
		background-image: linear-gradient(90deg, #FE9543 14%, #FF664F 100%);
		border-radius: 45upx;
		margin-top: 77upx;
		vertical-align: middle;
	}
	.parent-clue-details-content{
		margin: 30upx;
		padding: 50upx 35upx 30upx 35upx;
		border-radius: 16upx;
		background-color: #ffffff;
	}
	.parent-clue-details-nav{
		background-color: #ffffff;
	}
	.group-state-contain{
		width: 500upx;
		height: 64upx;
		margin-left: 60upx;
		line-height: 64upx;
		display: flex;
		background: #F2F2F2;
		border-radius: 32upx;
	}
	.group-state-contain>view{
		width: 50%;
		text-align: center;
		color: #666666;
		font-size: 28upx;
		border-radius: 32upx;
	}
	.group-state-contain .group-state-active{
		background: linear-gradient(to right,#FE9543,#FF664F);
		color: #FFFFFF;
	}
	.parent-clue-details-block{
		margin-top: 40upx;
	}
	.parent-clue-details-block-img{
		width: 620upx;
		height: 400upx;
		margin-bottom: 20upx;
		border-radius: 10upx;
	}
	.parent-clue-details-block-title{
		font-size: 28upx;
		font-weight: bold;
		margin-bottom: 20upx;
	}
	.parent-clue-details-block-look{
		position: absolute;
		right: 70upx; 
		display: inline-block; 
		color: #E41D1D;
	}
	.parent-clue-details-content-people{
		margin-top: 40upx;
		border-radius: 16upx;
		background-color: #ffffff;
		color: rgba(0,0,0,0.85);
		font-size: 24upx;
	}
	.arrow{
		display: inline-block;
		position: absolute;
		right: 90upx;
		margin-top: 50upx;
		width: 26upx;
		height: 26upx;
		border-top: 4upx solid #999;
		border-right: 4upx solid #999;
		transform: rotate(45deg);
	}
</style>
